package org.sy.lab.多线程基础._4_执行器._2_Future线程控制._4_取消任务;

import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main {

	public static void main(String[] args) {
		
		ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
		
		MyCallable myCallable = new MyCallable();
		
		Future<String> result = executor.submit(myCallable);
		System.out.println("isCancelled：" + result.isCancelled());
		System.out.println("isDone：" + result.isDone());
		try {
			TimeUnit.SECONDS.sleep(2);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("取消任务");
		result.cancel(true);
		System.out.println("isCancelled：" + result.isCancelled());
		System.out.println("isDone：" + result.isDone());
		executor.shutdown();
	}
}
